{include 'header.tpl'}
<div class="contant">
    <div class="header">
        <div class="header_s">
            <span class="back"><a href="{$refer|default:'javascript:history.go(-1)'}"><i class="iconfont fan">&#xe679;</i></a></span>
            <span class="title">新增收货地址</span>
            <span class="add_ads"></span>
            <div class="clear"></div>
        </div>
    </div>
    <div class="adress_cont" style="padding-top: 56px;">
        <ul>
            <li>
                <span>姓名</span>
                <input name="contact" type="text" class="aderess_name" id="contact" value="{$smarty.get.contact}" tabindex="1" placeholder="请输入姓名">
            </li>

            <li class="cf">
                <span>性别</span>
                <div class="pay_cont">
                    <span class="pay_list_c1 {if empty($smarty.get.sex) or $smarty.get.sex eq 2}on{/if}" data-value="2">
                        <input type="radio" name="sex" value="2" class="radioclass">
                    </span><span>女士</span>
                    <span class="pay_list_c1 {if $smarty.get.sex eq 1}on{/if}" data-value="1">
                        <input type="radio" name="sex" value="1" class="radioclass">
                    </span><span>先生</span>
                </div>
            </li>
            <li><span>手机</span>
                <input name="phone" type="text" maxlength="11" class="aderess_name"
                       id="phone" value="{$smarty.get.phone}" tabindex="1" placeholder="请输入手机号">
            </li>
        </ul>
    </div>
    <div class="adress_cont">
        <ul>
            <li>
                <span>收货区域</span>
                <select id="county" class="adress_nas" title="1" {if $smarty.get.county}disabled{/if}>
                    <option value="芙蓉区" {if $smarty.get.county eq '芙蓉区'}selected{/if}>芙蓉区</option>
                    <option value="开福区" {if $smarty.get.county eq '开福区'}selected{/if}>开福区</option>
                    <option value="雨花区" {if $smarty.get.county eq '雨花区'}selected{/if}>雨花区</option>
                    <option value="岳麓区" {if $smarty.get.county eq '岳麓区'}selected{/if}>岳麓区</option>
                    <option value="天心区" {if $smarty.get.county eq '天心区'}selected{/if}>天心区</option>
                    <option value="岳麓区" {if $smarty.get.county eq '岳麓区'}selected{/if}>岳麓区</option>
                    <option value="长沙县" {if $smarty.get.county eq '长沙县'}selected{/if}>长沙县</option>
                    <option value="望城县" {if $smarty.get.county eq '望城县'}selected{/if}>望城县</option>
                </select>
            </li>
            <li class="cf">
                <span>收货地址</span>
                <div class="adress_adv" id="baidumap">
                    <em><img src="/mall2/images/adty.png"></em>
                    {$smarty.get.address|default:'点击选择'}
                </div>
                <input type="hidden" name="id" id="id" value="{$smarty.get.id}"/>
                <input type="hidden" name="province" id="province" value="{$smarty.get.province}"/>
                <input type="hidden" name="city" id="city" value="{$smarty.get.city}"/>
                <input type="hidden" name="address" id="address" value="{$smarty.get.address}"/>
                <input type="hidden" name="lng" id="lng" value="{$smarty.get.lng}"/>
                <input type="hidden" name="lat" id="lat" value="{$smarty.get.lat}"/>
                <input type="hidden" name="refer" id="refer" value="{$refer}"/>
            </li>
            <li>
                <span>详细地址</span>
                <input class="aderess_name2" id="housemember" name="housemember" value="{$smarty.get.housemember}" tabindex="1" placeholder="详细到楼栋和门号">
            </li>
        </ul>
    </div>
    <div class="ader_btn" id="btn-save"><a href="#">保存</a></div>
    {if $smarty.get.id gt 0}<div class="detel_btn" id="btn-del"><a href="#">删除</a></div>{/if}
</div>
<script>
    $(function () {
        $('#baidumap').click(function () {
            var id = '{$id}';
            var contact = $('#contact').val() || '';
            var phone=$('#phone').val() || '';
            var sex = $(".pay_list_c1.on").data('value');
            var housemember=$('#housemember').val();
            var county=$('#county').find("option:selected").val();
            var refer = $('#refer').val();
            location.href='/address/baiduMap?id=' + id + '&contact=' + contact +
                            '&phone=' + phone + '&sex=' + sex + '&housemember=' + housemember + '&county=' + county + '&refer=' + refer;
        });
        $(".pay_list_c1").on("click",function(){
            $(this).addClass("on").siblings().removeClass("on");
        });
        $('#btn-del').click(function () {
            if(confirm('确定是否删除？')){
                var params = { };
                params.id = $('#id').val();
                var refer = $('#refer').val();
                $.post('/address/del',params,function(res){
                    if(res.status == 0){
                        window.location.href = '/address/list?refer=' + refer;
                    }
                });
            }
        });
        $('#btn-save').click(function () {
            var params = { };
            params.id = $('#id').val();
            params.refer = $('#refer').val();
            params.contact = $('#contact').val();
            params.phone=$('#phone').val();
            params.sex = $(".pay_list_c1.on").data('value');
            params.province= $("#province").val();
            params.city= $("#city").val();
            params.address= $("#address").val();
            params.county= $("#county").find("option:selected").val();
            params.lng=$("#lng").val();
            params.lat=$("#lat").val();
            params.housemember=$('#housemember').val();

            if(params.province == '' || params.city==''
                || params.lng=='' || params.lat==''
                || params.address == ''){
                $.alert("请选择收货地址");
                return false;
            }

            if(params.contact.length == 0  ){
                $.alert("姓名不能为空");
                return false;
            }

            if(params.phone == ''){
                $.alert("请输入手机号");
                return false;
            }

            //手机号码验证
            if(params.phone.length != 11){
                $.alert("手机号不正确！");
                return false;
            }
            if(params.housemember.length == 0  ){
                $.alert("门牌号不能为空");
                return false;
            }

            /*if(params.phone.length!=11)
            {
                alert('请输入有效的手机号码！');
                return false;
            }
            if(!(/^1[34578]\d\d\d\d\d\d\d\d\d$/.test(params.phone))){
                alert("手机号码有误，请重填");
                return false;
            }*/
            $.post('/address/save',params,function(res){
                if(res.status == 0){
                    window.location.href = res.url;
                }else{
                    $.alert(res.msg);
                }
            });
        });
    });
</script>
{include 'footer.tpl'}